home *** CD-ROM | disk | FTP | other *** search
- /*
- PPDRV -- Test ADI printer plotter driver
-
- This driver can either print a printer plot binary file
- written by the generic printer plotter code or be installed
- as a resident driver.
- */
-
- #include <stdio.h>
-
- #define VECTOR 0x7B /* Interrupt vector for installation */
-
- #define FALSE 0
- #define TRUE 1
-
- #define putprint(q) bdos(5, q) /* Send character to printer */
-
- /* Command codes for processing routine */
-
- #define FILELEVEL 1 /* Generic plot file format level */
-
- #define BEGINPLOT 0x8001 /* Begin plot */
- #define ENDPLOT 0x8002 /* End of plot */
- #define ABORTPLOT 0x8003 /* Plot terminated by user */
-
- static short install = FALSE; /* Install as resident driver */
- static FILE *fp; /* Input file pointer */
- static short gotfile = FALSE; /* Obtained file flag */
- static char tbfr[132];
- static short icode; /* Length / command code */
- struct pregs {
- unsigned ax, bx, cx, dx;
- };
- static struct pregs r;
- static struct {
- short level, xdots, ydots, colour;
- }
- cfg;
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- short i, j, m;
- char *cp, opt;
- register short c;
- char bbuf[1000]; /* Bit buffer */
-
- for (i=1; i < argc; i++) {
- cp = argv[i];
- if (*cp == '-') {
- opt = *(++cp);
- if (islower(opt))
- opt = toupper(opt);
- switch (opt) {
-
- case 'I':
- install = TRUE;
- break;
-
- case '?':
- help();
- exit();
- }
- }
- else {
- if (gotfile) {
- printf("\nDuplicate file name.");
- exit(1);
- }
- strcpy(tbfr, cp);
- strcat(tbfr, ".prp");
- if (fp = fopen(tbfr, "rb"))
- gotfile = TRUE;
- else {
- printf("\nCannot open file %s", tbfr);
- exit(1);
- }
- }
- }
- if (!gotfile & !install) {
- help();
- exit(1);
- }
-
- if (install) {
- fprintf(stderr, "Printer plotter driver installed at %03xh", VECTOR);
- while (1) {
- iwait(VECTOR, &r, &r);
- icode = r.ax;
- if (icode == ENDPLOT) {
- putprint('\14'); /* Form feed */
- fprintf(stderr, "\nEnd plot.\n");
- }
- else if (icode == BEGINPLOT) {
- fprintf(stderr, "Begin plot: interface level %d. %d by %d\n",
- r.bx, r.cx, r.dx);
- r.ax = TRUE; /* Say initialised OK */
- r.bx = FALSE; /* Select monochrome */
- }
- else if (icode == ABORTPLOT) {
- fprintf(stderr, "\nPlot aborted.\n");
- }
- else {
- if (icode & 0x8000) {
- fprintf(stderr, "\n** Undefined control code %04xh **\n", icode);
- }
- if (icode) {
- peek(r.cx, r.bx, bbuf, icode);
- for (i = 0; i < icode; i++)
- for (m = 0x80, j = 0; j < 8; j++, m >>= 1)
- putprint((bbuf[i] & m) ? '*' : ' ');
- }
- putprint('\n');
- }
- }
- }
-
- while (TRUE) {
- fread(&icode, sizeof icode, 1, fp);
- if (icode == ENDPLOT) {
- putprint('\14'); /* Form feed */
- fprintf(stderr, "End plot.");
- break;
- }
- else if (icode == BEGINPLOT) {
- fread(&cfg, sizeof cfg, 1, fp);
- fprintf(stderr, "Begin plot: interface level %d. %d by %d %s\n",
- cfg.level, cfg.xdots, cfg.ydots,
- cfg.colour ? "colour" : "monochrome");
- }
- else {
- if (icode & 0x8000) {
- printf("\n** Undefined control code %04xh **", icode);
- break;
- }
- if (icode)
- fread(bbuf, icode, 1, fp);
- for (i = 0; i < icode; i++)
- for (m = 0x80, j = 0; j < 8; j++, m >>= 1)
- putprint((bbuf[i] & m) ? '*' : ' ');
- putprint('\n');
- }
- }
-
- fclose(fp);
- }
-
- /* HELP -- Print information on how to call */
-
- static help()
- {
- printf("\nPPDRV -- Printer plotter driver. Call");
- printf("\n with PPDRV [options] input-file");
- printf("\n");
- printf("\n Options: -I Install as INT %02xh",
- VECTOR);
- }
-